﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.TypeNumber;

namespace FwProject.Manager
{
    public class TypeNumberInfoManager: IDomainService
    {
        private readonly IRepository<TypeNumberInfo, Guid> _typenumberRepository;
        public TypeNumberInfoManager(IRepository<TypeNumberInfo, Guid> typenumberRepository)
        {
            _typenumberRepository = typenumberRepository;

        }
        /// <summary>
        /// 添加一个型号
        /// </summary>
        /// <param name="typenumber"></param>
        /// <returns></returns>
        public async Task<Guid> CreateTypenumber(TypeNumberInfo typenumber)
        {
            var model = _typenumberRepository.GetAll().Where(o => o.Name == typenumber.Name).FirstOrDefault();
            if (model != null)
                throw new UserFriendlyException("该型号已存在");
                
            return await _typenumberRepository.InsertAndGetIdAsync(typenumber);
        }
        /// <summary>
        ///修改一个型号
        /// </summary>
        /// <param name="typenumber"></param>
        /// <returns></returns>
        public async Task UpdateTypenumber(TypeNumberInfo typenumber)
        {

            await _typenumberRepository.UpdateAsync(typenumber);
        }
        /// <summary>
        ///  delete 一个型号
        /// </summary>
        /// <param name="typenumber"></param>
        /// <returns></returns>
        public async Task DeleteTypenumber(TypeNumberInfo typenumber)
        {

            await _typenumberRepository.DeleteAsync(typenumber);
        }
    }
}
